home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / dfue / term 4.6(?) / extras / source / gtlayout-source.lha / LTP_BitMap.c < prev    next >
C/C++ Source or Header  |  1996-03-18  |  1KB  |  79 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. LONG
  15. LTP_GetDepth(struct BitMap *BitMap)
  16. {
  17.     if(V39)
  18.         return((LONG)GetBitMapAttr(BitMap,BMA_DEPTH));
  19.     else
  20.         return(BitMap->Depth);
  21. }
  22.  
  23. VOID
  24. LTP_DeleteBitMap(struct BitMap *BitMap,BOOL Chip)
  25. {
  26.     if(V39 && !Chip)
  27.         FreeBitMap(BitMap);
  28.     else
  29.     {
  30.         if(BitMap)
  31.         {
  32.             LONG i;
  33.  
  34.             for(i = 0 ; i < BitMap->Depth ; i++)
  35.                 FreeVec(BitMap->Planes[i]);
  36.  
  37.             FreeVec(BitMap);
  38.         }
  39.     }
  40. }
  41.  
  42. struct BitMap *
  43. LTP_CreateBitMap(LONG Width,LONG Height,LONG Depth,struct BitMap *Friend,BOOL Chip)
  44. {
  45.     struct BitMap *BitMap;
  46.  
  47.     if(V39 && !Chip)
  48.         BitMap = AllocBitMap(Width,Height,Depth,BMF_MINPLANES,Friend);
  49.     else
  50.     {
  51.         if(BitMap = (struct BitMap *)AllocVec(sizeof(struct BitMap),MEMF_ANY | MEMF_PUBLIC))
  52.         {
  53.             LONG PageSize;
  54.             LONG i;
  55.  
  56.             InitBitMap(BitMap,Depth,Width,Height);
  57.  
  58.             PageSize = BitMap->BytesPerRow * BitMap->Rows;
  59.  
  60.             for(i = 0 ; i < Depth ; i++)
  61.             {
  62.                 if(!(BitMap->Planes[i] = (PLANEPTR)AllocVec(PageSize,MEMF_CHIP)))
  63.                 {
  64.                     LONG j;
  65.  
  66.                     for(j = 0 ; j < i ; j++)
  67.                         FreeVec(BitMap->Planes[j]);
  68.  
  69.                     FreeVec(BitMap);
  70.  
  71.                     return(NULL);
  72.                 }
  73.             }
  74.         }
  75.     }
  76.  
  77.     return(BitMap);
  78. }
  79.